package com.itcast.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
/*
切面类对方法增强
 */

//@Component//注入容器
@Slf4j
//@Aspect//标注切面类
public class DemoAspect {
    /**
     *通知方法
     * proceedingJoinPoint中封装了方法相关的信息
     */
    @Around("execution(* com.itcast.service.impl.DeptServiceImpl.*(..))")
    public Object DemoAspect(ProceedingJoinPoint joinPoint) throws Throwable{
        log.info("执行方法增强");
        long begin = System.currentTimeMillis();
        //执行方法
        Object result = joinPoint.proceed();
        long end = System.currentTimeMillis();
        log.info("执行方法耗时{}ms",end-begin);
        return result;
    }
}

